<template>
  <div>
    <home-header></home-header>
    <home-swiper></home-swiper>
    <home-icons></home-icons>
    <home-recommend></home-recommend>
    <home-weekend></home-weekend>
  </div>
</template>

<script>
import HomeHeader from "./components/Header";
import HomeSwiper from "./components/Swiper";
import HomeIcons from "./components/Icons";
import HomeRecommend from "./components/Recommend";
import HomeWeekend from "./components/Weekend";
import axios from "axios";
import { mapState } from "vuex";
export default {
  name: "Home",
  computed: {
    ...mapState(["city"]),
  },
  components: {
    HomeHeader,
    HomeSwiper,
    HomeRecommend,
    HomeWeekend,
    HomeIcons,
  },
  data() {
    return {
      lastCity: "",
    };
  },

  methods: {
    async loadIndex() {
      await axios
        .get("http://192.168.0.5:8080/index.json?city=" + this.city)
        .then((res) => {
          res = res.data;
          if (res.ret && res.data) {
          }
        });
    },
  },
  mounted() {
    this.lastCity = this.city;
    this.loadIndex();
  },
  // 页面重新显示的时候页面可以判断当前页面城市与城市是否相同
  activated() {
    if (this.lastCity !== this.city) {
      // 只有页面被刷新的时候才发送一次
      this.lastCity = this.city;
      this.loadIndex();
    }
  },
};
</script>

<style>
</style>